package com.spirng.leetcode.day03;

import java.util.HashSet;

public class Intersection {
    public int[] intersection(int[] nums1, int[] nums2) {
        HashSet<Integer> hashSet = new HashSet<>();
        HashSet<Integer> result = new HashSet<>();
        for (int i = 0; i < nums1.length; i++) {
            hashSet.add(nums1[i]);
        }
        for (int i = 0; i < nums2.length; i++) {
            if(hashSet.contains(nums2[i])){
                result.add(nums2[i]);
            }
        }
        int []arr=new int[result.size()];
        int j=0;
        for (Integer i : result) {
            arr[j++]=i;
        }
        return arr;
    }
}
